<!--头部公共部分-->
{include file="common/header" /}
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a><cite>新增课程包</cite></a>
      </span>
    <a class="layui-btn layui-btn-xs layui-btn-small" style="margin-top:7px;float:right;margin-left: 10px;"
       href="{:url('package/package_manage')}">
        返回课程包管理</a>

</div>
<div style="padding:15px;">
    <div class="layui-tab">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form" action="" method="POST">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>课程</label>
                            <div class="layui-input-inline">
                                <input type="text"  value="{$package.course}" readonly  autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>年份</label>
                            <div class="layui-input-inline">
                                <select name="year" lay-verify="required" lay-search="">
                                    {volist name="data[12]" id="v"}
                                    <option value="{$v.id}"{if $package.year == $v.id}selected{/if}>{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>年级</label>
                            <div class="layui-input-inline">
                                <select name="grade" lay-verify="required" lay-search="">
                                    {volist name="data[1]" id="v"}
                                    <option value="{$v.id}" {if $package.grade == $v.id}selected{/if}>{$v['name']}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label"><span style="color: red;">*</span>课程包名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="name" value="{$package.name}" readonly autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">结算信息</label>
                        <div class="layui-inline">
                            <div class="layui-form-mid layui-word-aux">课程总额</div>
                            <div class="layui-input-inline">
                                <input type="text" name="totalprice" id="money" value="{$package.totalprice}" readonly placeholder="" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">元</div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid layui-word-aux">课程包优惠</div>
                            <div class="layui-input-inline">
                                <input type="text" name="discount" id="youhui" oninput="myFunction()" value="{$package.discount}" placeholder="0" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">元</div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form-mid layui-word-aux">课程应收</div>
                            <div class="layui-input-inline">
                                <input type="text" name="receivable" id="yingshou" value="{$package.receivable}" readonly placeholder="" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid layui-word-aux">元</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$id}">
                            <input class="layui-btn" lay-submit lay-filter="wxsubmit" id="sub" value="立即提交" readonly>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!--底部公共部分-->
{include file="common/footer" /}


<script>
    function myFunction() {
        var x = document.getElementById("youhui").value;
        console.log(x);
        var money = $('input[name=totalprice]').val();
        console.log(money);
        if(Number(x) > Number(money)){
            layer.msg('优惠金额不能大于总金额，请重新输入');
            $('#yingshou').val('');
            $('#youhui').val('');
            return false;
        }
        var data = (Number(money) - Number(x));
        console.log(data);
        $('#yingshou').val(data);
    }

    layui.use(['jquery','element', 'form','layer'], function(){
        var $ = layui.jquery,
            layer = layui.layer,
            element = layui.element,
            form = layui.form;

        form.on('submit(wxsubmit)', function (data) {
            var field = data.field;
            $.ajax({
                type: 'post',
                url: '{:url("package/edit")}',
                data: field,
                success: function (result) {
                    if (result.code === 0) {
                        layer.msg(result.msg, {time: 2000});
                    }else {
                        layer.msg(result.msg, {time: 2000});
                    }
                    setTimeout(function () {
                        location.href = '{:url("package/package_manage")}';
                    }, 2000)
                }
            });
        });
    });
</script>
